<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
      
        <!-- 搜索 -->
        <template>
          <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
            <el-form-item label="用户昵称" prop="nickName">
              <el-input
                v-model="queryParams.nickName"
                placeholder="请输入用户昵称"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="邀请者ID" prop="inviteId">
              <el-input
                v-model="queryParams.inviteId"
                placeholder="请输入邀请者ID"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="激活状态" prop="active">
              <el-select
                v-model="queryParams.active"
                placeholder="用户激活状态"
                clearable
                style="width: 240px"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="店铺ID" prop="shopId" v-if="$store.getters && $store.getters.admin">
              <el-input
                v-model="queryParams.shopId"
                placeholder="请输入店铺ID"
                clearable
                style="width: 240px"
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="dateRange"
                style="width: 240px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
              <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </template>

        <!-- 表格 -->
        <template>
          <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange" :default-sort="defaultSort" @sort-change="handleSortChange">
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column type="index" label="序号" width="50" align="center" />
            <el-table-column label="邀请者Id" align="center" key="inviteId" prop="inviteId" />
            <el-table-column label="被邀客户" align="left" key="nickName" prop="nickName" :show-overflow-tooltip="true" min-width="150" >
              <template slot-scope="scope">
                <div class="flex-align-center" v-if="scope.row">
                  <el-avatar shape="circle" size="medium" :src="scope.row.avatar" alt="404"></el-avatar>
                  <div class="mgl5 font-14">{{scope.row.nickName}}</div>
                </div>
                <div v-else>-</div>
              </template>
            </el-table-column>
            <el-table-column label="店铺名称" prop="shopInfo.shopName" v-if="$store.getters && $store.getters.admin" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="160" sortable="custom" :sort-orders="['descending', 'ascending']">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.createTime) }}</span>
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页 -->
          <pagination
            v-show="total>0"
            :total="total"
            :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize"
            @pagination="getList"
          />
        </template>

      </el-col>
    </el-row>

  </div>
</template>

<script>
import { listUser } from "@/api/customer/user";

export default {
  name: "CustomerInvite",
  dicts: [],
  components: { },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 默认排序
      defaultSort: {prop: 'createTime', order: 'descending'},
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
        phonenumber: undefined,
        shopId: undefined,
        orderByColumn: 'createTime',
        isAsc: 'descending',
        params: {
          inviteId: 'inviteId'
        }
      },
    };
  },
  watch: {
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.queryParams.deptId = undefined;
      this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
  }
};
</script>